import requests


def _link(cookie):
    linkhub = "https://linkhub.cool/user/checkin"

    linkhub_headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
                      "Chrome/73.0.3683.103 Safari/537.36",
        "Cookie": cookie}
    res = requests.post(url=linkhub, headers=linkhub_headers)

    try:
        return res.json()['msg']
    except:
        return "貌似失效了..."


def link(email, passwd):
    ses = requests.session()

    login_url = 'https://linkhub.cool/auth/login'
    header = {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
                            "Chrome/73.0.3683.103 Safari/537.36"}

    data = {'email': email, 'passwd': passwd, 'code': '', 'remember_me': 'on'}
    ses.post(url=login_url, data=data, headers=header)
    ses.get('https://linkhub.cool/user', headers=header)
    res = ses.post('https://linkhub.cool/user/checkin', headers=header).json()
    try:
        return res['msg']
    except:
        return "貌似失效了..."
